package listener;

import ioc.listener.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class ContextLoaderListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("context 初始化");
        ServletContext servletContext = servletContextEvent.getServletContext();
        String path = servletContext.getInitParameter("");
        ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext(path);
        servletContext.setAttribute("beanFactory",beanFactory);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("context 销毁");
    }
}
